/*
 *
 *  Copyright (C) 2010 GSyC/LibreSoft, Universidad Rey Juan Carlos.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *
 *  Author : Raúl Román López <rroman@gsyc.es>
 *
 */

package com.LibreGeoSocial.App.Tagging;

import android.location.Location;

import com.LibreGeoSocial.App.AR.Overlays.DrawResource;
import com.LibreGeoSocial.App.Utils.LocationUtils;


public class AngleTag{
	
private static final int MAX_POINTS = 2;
	
	private TagElem[] tagElem;
	private int counter;
	
	
	public AngleTag(){
		this.tagElem = new TagElem[MAX_POINTS];
		counter = 0;
	}
	
	public boolean addElem(float[] loc, float orientation, float elevation){
		
		Location location = new Location("");
		location.setLatitude(loc[0]);
		location.setLongitude(loc[1]);
		
		TagElem tag_elem = new TagElem(location, orientation, elevation);
		
		tagElem[counter] = tag_elem; 
		counter++;
		
		if(counter >= MAX_POINTS)
			//end
			return true;
		
		return false;
	}
	
	public float[] getLocationArray(){
		
		float[] user_location = tagElem[0].getPosition();
		float orientation0 = tagElem[0].getOrientation();
		float orientation1 = tagElem[1].getOrientation();
		
		float angle = tagElem[1].getOrientation();
		
		if((tagElem[0].getOrientation() > 270) && (angle < 135)){
			angle += 360;
		}
		
		float theta = Math.abs(angle - tagElem[0].getOrientation());
		float alpha = DrawResource.MAX_AZIMUTH_VISIBLE;
		float camDistance = LocationUtils.DEV_DISTANCE;
		
		return LocationUtils.calculateAngleIntersection(user_location, 
				orientation0, orientation1, theta, alpha, tagElem[1].getElevation(), camDistance);
		
	}
	
}